/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.teaching_award.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.teaching_award.entity.TbTeachingAward;
import com.thinkgem.jeesite.modules.teaching_award.service.TbTeachingAwardService;

/**
 * 教学成果奖Controller
 * @author hang
 * @version 2017-01-14
 */
@Controller
@RequestMapping(value = "${adminPath}/teaching_award/tbTeachingAward")
public class TbTeachingAwardController extends BaseController {

	@Autowired
	private TbTeachingAwardService tbTeachingAwardService;
	
	@ModelAttribute
	public TbTeachingAward get(@RequestParam(required=false) String id) {
		TbTeachingAward entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tbTeachingAwardService.get(id);
		}
		if (entity == null){
			entity = new TbTeachingAward();
		}
		return entity;
	}
	
	@RequiresPermissions("teaching_award:tbTeachingAward:view")
	@RequestMapping(value = {"list", ""})
	public String list(TbTeachingAward tbTeachingAward, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TbTeachingAward> page = tbTeachingAwardService.findPage(new Page<TbTeachingAward>(request, response), tbTeachingAward); 
		model.addAttribute("page", page);
		return "modules/teaching_award/tbTeachingAwardList";
	}

	@RequiresPermissions("teaching_award:tbTeachingAward:view")
	@RequestMapping(value = "form")
	public String form(TbTeachingAward tbTeachingAward, Model model) {
		model.addAttribute("tbTeachingAward", tbTeachingAward);
		return "modules/teaching_award/tbTeachingAwardForm";
	}

	@RequiresPermissions("teaching_award:tbTeachingAward:edit")
	@RequestMapping(value = "save")
	public String save(TbTeachingAward tbTeachingAward, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tbTeachingAward)){
			return form(tbTeachingAward, model);
		}
		tbTeachingAwardService.save(tbTeachingAward);
		addMessage(redirectAttributes, "保存教学成果奖成功");
		return "redirect:"+Global.getAdminPath()+"/teaching_award/tbTeachingAward/?repage";
	}
	
	@RequiresPermissions("teaching_award:tbTeachingAward:edit")
	@RequestMapping(value = "delete")
	public String delete(TbTeachingAward tbTeachingAward, RedirectAttributes redirectAttributes) {
		tbTeachingAwardService.delete(tbTeachingAward);
		addMessage(redirectAttributes, "删除教学成果奖成功");
		return "redirect:"+Global.getAdminPath()+"/teaching_award/tbTeachingAward/?repage";
	}

}